﻿using System;
using System.Reflection;
using System.Runtime.Serialization;

namespace Creventive.Wpf.ShellFactory.Modules
{
    /// <summary>
    ///   Represents errors which occur while loading modules.
    /// </summary>
    [Serializable]
    public class ModuleLoadException : Exception
    {
        /// <summary>
        ///   Initializes a new instance of the <see cref = "ModuleLoadException" /> class.
        /// </summary>
        public ModuleLoadException()
        {}

        /// <summary>
        ///   Initializes a new instance of the <see cref = "ModuleLoadException" /> class.
        /// </summary>
        /// <param name = "moduleAssemblyName">Name of the module assembly.</param>
        /// <param name = "message">The message.</param>
        public ModuleLoadException(AssemblyName moduleAssemblyName, string message)
            : base(message)
        {
            this.ModuleAssemblyName = moduleAssemblyName;
        }

        /// <summary>
        ///   Initializes a new instance of the <see cref = "ModuleLoadException" /> class.
        /// </summary>
        /// <param name = "moduleAssemblyName">Name of the module assembly.</param>
        /// <param name = "message">The message.</param>
        /// <param name = "inner">The inner.</param>
        public ModuleLoadException(AssemblyName moduleAssemblyName, string message, Exception inner)
            : base(message, inner)
        {
            this.ModuleAssemblyName = moduleAssemblyName;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ModuleLoadException"/> class.
        /// </summary>
        /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
        /// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="info"/> parameter is null. </exception>
        /// <exception cref="T:System.Runtime.Serialization.SerializationException">The class name is null or <see cref="P:System.Exception.HResult"/> is zero (0). </exception>
        protected ModuleLoadException(
            SerializationInfo info,
            StreamingContext context)
            : base(info, context)
        {}

        /// <summary>
        ///   Gets the name of the module assembly which failed to load.
        /// </summary>
        /// <value>The name of the module assembly.</value>
        public AssemblyName ModuleAssemblyName { get; private set; }
    }
}